/*
 *===================================================================
 *
 *          Name: util.h
 *        Create: Fri 01 Jun 2012 06:45:15 PM CST
 *
 *   Discription: some usefull functions
 *       Version: 1.0.0
 *
 *        Author: yuwei.zhang
 *         Email: yuwei.zhang@besovideo.com
 *
 *===================================================================
 */
#ifndef __UTIL_H
#define __UTIL_H

#include "stdint.h"


/*
 * func: parse string to data[maxlen] with sign(",", xxx)
 * @param data --> array to store
 * @param string -->  string to parse
 * source: "0x02,0x03..."
 * result: 0x02 0x03 ....
 */
int _parse_data(unsigned char *data, char *string);

/*
 * func: just like _parse_data above
 * @param maxlen -->  what counts to get
 * @param sign -->  what sign , ? ! : .....
 * source: x,c,b,
 * result: x c b
 */
int _parse_data_char(unsigned char *data, char *string, int maxlen, const char *sign);

/*
 * func: like above
 * @param data  data[][]
 * @param sign  a char (, . .....)
 */
#define MAX_EACH_DATA_STRING          256
int _parse_data_string(char data[][MAX_EACH_DATA_STRING], char *string, int maxlen, const char sign);

/*
 * func: upgrade of up func
 * warn: we memset save[0] + arrsize*maxlen
 * @string: string to do like ex: xxx,xxxx,xx
 * @save: array to save result ex: save[10][8]
 * @arrsize: each array size ex:8 (the last is '\0', so only save arrsize-1 chars)
 * @maxlen: how many arrays ex:10
 * @sign: ex: , ? :
 */
int _parse_data_string2(char *string, char *save, int arrsize, int maxlen, const char sign);

/* func: parse string to get int
 * parse sign
 * (%d,%d....)
 */
int _parse_string_int(char *string, int *save, int maxlen, const char *sign);

/*
 * (xxxx,xxxsaf) ==> xxxx,xxxaf  only support only one ( ) pair and 
 * position first and last
 */
int clear_parenthesis(char *save, char *string);

char *GetIp(char *dn_or_ip, const char *eth);


/*
 * malloc data
 */
int resize_data(char **data, int protobuflen, char* protobufdata);


/*
 * check if device contain device(string) is mounted 
 * it check /proc/mounts
 * return 1: has mounted
 *        0: not mounted 
 *        other: errno
 */
int MC_is_mounted(char *device);

/*
 * func: remove the last \n if is
 */
int MC_RemoveLastBreak(char *args);

/* 
 * get flow , of bytes
 * interface: "eth0", "ppp1",....
 */
int MC_getflow(const char *interface, unsigned long long *recv, unsigned long long *send, unsigned long long *total);

#endif // __UTIL_H

/*=============== End of file: util.h =====================*/
